package cn.oms.oms.controller;

import cn.oms.oms.entity.Staff;
import cn.oms.oms.service.IStaffService;
import cn.oms.oms.vo.StaffVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/staff")
@Slf4j
public class StaffController {

    @Autowired
    public IStaffService staffService;


    /**
     * 根据查询条件查询员工列表
     * @param staffVo
     * @return
     */
    @PostMapping("/selectStaffList")
    public PageInfo<Staff> selectStaffList(StaffVo staffVo){
        if(staffVo.getPageNum()==null||staffVo.getPageNum()==0){
            staffVo.setPageNum(1);
        }
        if(staffVo.getPageSize()==null||staffVo.getPageSize()==0){
            staffVo.setPageSize(5);
        }
        log.debug("接收到信息:{}",staffVo);
        PageInfo<Staff> pageInfo = staffService.selectStaffList(staffVo);
        return pageInfo;
    }

    /**
     * 查询员工详情
     * @param staffVo
     * @return
     */
    @PostMapping("/selectStaffDetail")
    public Staff selectStaffDetail(StaffVo staffVo){
        log.debug("接收到信息:{}",staffVo);
        Staff staff = staffService.selectStaffDetail(staffVo);
        return staff;
    }

    /**
     * 新增员工
     * @param staffVo
     * @return
     */
    @PostMapping("/addStaff")
    public String addStaff(StaffVo staffVo){
        log.debug("接收到信息:{}",staffVo);
        String res = staffService.addStaff(staffVo);
        return res;
    }
    /**
     * 修改员工
     * @param staffVo
     * @return
     */
    @PostMapping("/updateStaff")
    public String updateStaff(StaffVo staffVo){
        log.debug("接收到信息:{}",staffVo);
        String res = staffService.updateStaff(staffVo);
        return res;
    }
    /**
     * 删除员工
     * @param id
     * @return
     */
    @GetMapping("/deleteStaff/{id}")
    public String deleteStaff(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = staffService.deleteStaff(id);
        return res;
    }

}
